home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / visulztn / saoimage / saoimage.lha / grphdraw.c < prev    next >
C/C++ Source or Header  |  1990-04-20  |  5KB  |  179 lines

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    grphdraw.c (Color Graph Draw)
  6.  * Purpose:    Draw color graph lines
  7.  * Subroutine:    draw_colorbar()                returns: void
  8.  * Subroutine:    draw_cgraph()                returns: void
  9.  * Subroutine:    highlight_active_cgraph_vertex()    returns: void
  10.  * Subroutine:    install_draw_queue_end()        returns: void
  11.  * Subroutine:    replace_draw_queue_end()        returns: void
  12.  * Xlib calls:    XPutImage(), XDrawLines(), XDrawRectangles(), XFillRectangles()
  13.  * Copyright:    1989 Smithsonian Astrophysical Observatory
  14.  *        You may do anything you like with this file except remove
  15.  *        this copyright.  The Smithsonian Astrophysical Observatory
  16.  *        makes no representations about the suitability of this
  17.  *        software for any purpose.  It is provided "as is" without
  18.  *        express or implied warranty.
  19.  * Modified:    {0} Michael VanHilst    initial version         11 June 1989
  20.  *        {1} MVH added graphbox colorbar to draw_colorbar  21 Oct 1989
  21.  *        {n} <who> -- <does what> -- <when>
  22.  */
  23.  
  24. #include <stdio.h>        /* stderr, NULL, etc. */
  25. #include <X11/Xlib.h>        /* X window stuff */
  26. #include <X11/Xutil.h>        /* X window manager stuff */
  27. #include "hfiles/color.h"    /* color structs */
  28. #include "hfiles/cgraph.h"    /* color graph structs */
  29.  
  30. extern struct cgraphRec cgraph;
  31. extern struct colbarRec colorbar;
  32.  
  33. /*
  34.  * Subroutine:    draw_colorbar
  35.  * Purpose:    Put the color bar on the screen
  36.  * Xlib calls:    XPutImage()
  37.  */
  38. void draw_colorbar ( graph )
  39.      int graph;        /* i: graphbox colorbar, else colorbox colorbar */
  40. {
  41.   GC gc, set_gc(), set_gc_with_background();
  42.   if( cgraph.ncolors > 1 )
  43.     gc = set_gc(cgraph.disp);
  44.   else
  45.     gc = set_gc_with_background(cgraph.disp, cgraph.disp->background);
  46.   if( graph )
  47.     XPutImage(cgraph.bar.display, cgraph.bar.ID, gc, cgraph.bar.image,
  48.           0, 0, 0, 0, cgraph.bar.width, cgraph.bar.height);
  49.   else
  50.     XPutImage(colorbar.display, colorbar.ID, gc, colorbar.image,
  51.           0, 0, 0, 0, colorbar.width, colorbar.height);
  52. }
  53.   
  54. /*
  55.  * Subroutine:    draw_cgraph
  56.  * Purpose:    Draw the cgraph graph lines and hash marks
  57.  * Xlib calls:    XDrawLines(), XDrawRectangles()
  58.  */
  59. void draw_cgraph ( redo, highlight )
  60.      int redo;        /* i: recalculate-all-line-coordinates */
  61.      int highlight;    /* i: highlight-vertex-hash-being-manipulated */
  62. {
  63.   int i;
  64.   GC gc, set_gc();
  65.   int set_cgraph_hash();
  66.   void mark_colorline_overlap();
  67.   void highlight_active_cgraph_vertex(), set_cgraph_line();
  68.  
  69.   if( cgraph.inactive )
  70.     return;
  71.   XClearWindow(cgraph.graph.display, cgraph.graph.ID);
  72.   for( i=0; i<cgraph.queue_cnt; i++ ) {
  73.     if( redo || cgraph.queue[i]->unset ) {
  74.       if( cgraph.queue[i]->table->do_gamma )
  75.     set_cgraph_line(cgraph.queue[i]->table->gammamap,
  76.                 cgraph.queue[i]->line);
  77.       else
  78.     set_cgraph_line(cgraph.queue[i]->table->cellmap,
  79.             cgraph.queue[i]->line);
  80.       cgraph.queue[i]->hash_0 =
  81.     set_cgraph_hash(cgraph.queue[i]->table,
  82.             cgraph.queue[i]->hash, &cgraph.queue[i]->hash_cnt);
  83.       cgraph.queue[i]->unset = 0;
  84.     }
  85.     gc = set_gc(cgraph.queue[i]->draw);
  86.     XDrawLines(cgraph.graph.display, cgraph.graph.ID, gc,
  87.            cgraph.queue[i]->line, cgraph.point_cnt, CoordModeOrigin);
  88.   }
  89.   /* draw the hash marks */
  90.   for( i=0; i<cgraph.queue_cnt; i++ ) {
  91.     if( cgraph.queue[i]->hash_cnt ) {
  92.       gc = set_gc(cgraph.queue[i]->draw);
  93.       XDrawRectangles(cgraph.graph.display, cgraph.graph.ID, gc,
  94.               cgraph.queue[i]->hash, cgraph.queue[i]->hash_cnt);
  95.     }
  96.   }
  97.   if( highlight )
  98.     highlight_active_cgraph_vertex();
  99.   else
  100.     mark_colorline_overlap();
  101. }
  102.  
  103. /*
  104.  * Subroutine:    highlight_active_cgraph_vertex
  105.  * Purpose:    Draw active hash mark as filled box
  106.  * Xlib calls:    XFillRectangles()
  107.  */
  108. void highlight_active_cgraph_vertex ( )
  109. {
  110.   GCspec *draw;
  111.   XRectangle *hash = NULL;
  112.   if( cgraph.red.active ) {
  113.     hash = &cgraph.red.hash[cgraph.red.active_hash];
  114.     draw = cgraph.red.draw;
  115.   }
  116.   if( cgraph.green.active ) {
  117.     if( hash == NULL ) {
  118.       hash = &cgraph.green.hash[cgraph.green.active_hash];
  119.       draw = cgraph.green.draw;
  120.     } else
  121.       draw = cgraph.black;
  122.   }
  123.   if( cgraph.blue.active ) {
  124.     if( hash == NULL ) {
  125.       hash = &cgraph.blue.hash[cgraph.blue.active_hash];
  126.       draw = cgraph.blue.draw;
  127.     } else
  128.       draw = cgraph.black;
  129.   }
  130.   if( hash != NULL ) {
  131.     GC gc, set_gc();
  132.     gc = set_gc(draw);
  133.     XFillRectangles(cgraph.graph.display, cgraph.graph.ID, gc, hash, 1);
  134.   }
  135. }
  136.       
  137. /*
  138.  * Subroutine:    install_draw_queue_end
  139.  * Purpose:    Installed newly active line to be last drawn
  140.  */
  141. void install_draw_queue_end ( col )
  142.      struct colgRec *col;
  143. {
  144.   if( cgraph.queue_cnt != 3 )
  145.     return;
  146.   if( cgraph.queue[2] == col ) {
  147.     return;
  148.   } else if( cgraph.queue[1] == col ) {
  149.     cgraph.queue[1] = cgraph.queue[2];
  150.     cgraph.queue[2] = col;
  151.   } else if( cgraph.queue[0] == col ) {
  152.     cgraph.queue[0] = cgraph.queue[1];
  153.     cgraph.queue[1] = cgraph.queue[2];
  154.     cgraph.queue[2] = col;
  155.   }
  156. }
  157.  
  158. /*
  159.  * Subroutine:    replace_draw_queue_end
  160.  * Purpose:    Replace end of the draw queue when end color is no longer
  161.  *        active
  162.  */
  163. void replace_draw_queue_end ( )
  164. {
  165.   struct colgRec *col;
  166.   if( cgraph.queue_cnt != 3 )
  167.     return;
  168.   if( cgraph.queue[1]->active ) {
  169.     col = cgraph.queue[2];
  170.     cgraph.queue[2] = cgraph.queue[1];
  171.     cgraph.queue[1] = cgraph.queue[0];
  172.     cgraph.queue[0] = col;
  173.   } else if( cgraph.queue[0]->active ) {
  174.     col = cgraph.queue[2];
  175.     cgraph.queue[2] = cgraph.queue[0];
  176.     cgraph.queue[0] = col;
  177.   }
  178. }
  179.